<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form id="myform" action="#" method="post">
  书名:<input type="text" id="bookName"><br>
  作者:<input type="text" id="bookAuthor"><br>
  价格:<input type="text" id="bookPrice "><br>
  图片:<input type="text" id="bookImg"><br>
  日期:<input type="date" id="bookDate"><br>
  描述:<input type="text" id="bookDesc"><br>
  <input type="button" value="添加图书" id="addBook">
    <input type="button" value="返回" onclick="history.back()">
</form>
<script src="js/jq.js"></script>
<script>
    $(function (){
        $('#addBook').click(function (){
            //alert('添加成功');
            var obj = {
                bookName:$('#bookName').val(),
                bookAuthor:$('#bookAuthor').val(),
                bookPrice:$('#bookPrice').val(),
                bookImg:$('#bookImg').val(),
                bookDate:$('#bookDate').val(),
                bookDesc:$('#bookDesc').val()
            }
            console.log(obj);
            //使用jqajax发生请求
            $.ajax({
                url:'http://localhost:8081/book/add',//请求的路径
                type:'post',//ajax的请求方式
                data:obj,//发送到后端的数据
                success(){//请求成功后调用的方法
                    alert('添加成功');
                    //跳转页面，到所有数据页面
                    location.href='queryBook.html';
                }
            })
        });
    });
</script>
</body>

</html>